﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using myBoard.App.Components.MagnetsStore.ViewsModels;
using myBoard.App.MagnetStore;

namespace myBoard.App.Components.MagnetsStore
{
    /// <summary>
    /// Interaction logic for SubmitCommentControl.xaml
    /// </summary>
    public partial class SubmitCommentControl : UserControl
    {
        public delegate void CancelCommentRequestedHandler(SubmitCommentControl sender);
        public delegate void SubmitCommentRequestedHandler(MagnetComment comment);
        public event CancelCommentRequestedHandler CancelCommentRequested;
        public event SubmitCommentRequestedHandler SubmitCommentRequested;


        public SubmitCommentControl()
        {
            InitializeComponent();
            _cancelBt.Click += new RoutedEventHandler(_cancelBt_Click);
            _submitBt.Click += new RoutedEventHandler(_submitBt_Click);
        }

        void _submitBt_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(_commentDescription.Text) || string.IsNullOrEmpty(_commentTitleTbx.Text))
            {
                myBoard.Framework.Forms.MessageBox.Show("Review submission failed", 
                    "You must enter a title and a description for your review.",
                    "Magnet Store", System.Diagnostics.EventLogEntryType.Error);
                return;
            }

            if (myBoard.Framework.Forms.MessageBox.Show("Confirmation",
                "You can only submit one review per magnet, are you sure you want to validate this review ?",
                "Magnet Store", System.Diagnostics.EventLogEntryType.Warning, MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
                return;
            
    
            MagnetComment comment = new MagnetComment()
            {
                Description=_commentDescription.Text,
                Rating=_ratingControl.Rating,
                Title=_commentTitleTbx.Text
            };
            
            _commentDescription.Text = string.Empty;
            _ratingControl.Rating = 3;
            _commentTitleTbx.Text = string.Empty;

            if (SubmitCommentRequested != null)
                SubmitCommentRequested(comment);

        }

        void _cancelBt_Click(object sender, RoutedEventArgs e)
        {
            if (CancelCommentRequested != null)
                CancelCommentRequested(this);
        }
    }
}
